*** Replication File For

* Tepe, Vanhuysse & Lutz. 2020. Political Research Quarterly  
* Merit, Luck and Taxes. Societal Reward Rules, Self-Interest and Ideology in a Real-Effort Voting Experiment
* This Version 24. Aug. 2020

*** Load Dataset
use "~\PRQ_Data.dta", replace 

*** Preparing Vars 
recode treatment 1=2 2=3 3=4 4=5 5=1, gen(treat5)
label define treat5_lb 2 "Merit rule with full information" 3 "Luck rule with full information" 4 "Merit rule without information" 5 "Luck rule without information" 1 "Equal pay"
label values treat5 treat5_lb 
label var treat5 "Treatment condition"

label var rate "Productivity"
label var age "Age"
label var female "Female"
label var sem "Semester"

tab study, gen(study)
label var study1 "Natural science"
label var study2 "Other"
label var study3 "Social science"
label var study4 "Arts Humanities"
label var study5 "Business science"

* Partisan orientation
recode pol_selbstein  0=0 1=.1 2=.2 3=.33 4=.44 5=.5 6=.6 7=.7 8=.8 9=.9  10=1, gen(leftright)
su leftright
label var leftright "Left Right"

* Egoistic preference (continous)
sort sessionid period group subject
bysort groupid: egen bruttoincome_mean = mean(bruttoincome)
gen ginc_d = bruttoincome-bruttoincome_mean 
gen ginc_ln = ln(bruttoincome/bruttoincome_mean)
label var ginc_d  "Egoistic vote (cont.)"

* Dep Var.
gen decision01 = decision/100
label var decision01 "Tax rate"

* Merit = Equity
recode linos_b 1=5 2=4 3=3 4=2 5=1 , gen(linos_br) 
recode linos_h 1=5 2=4 3=3 4=2 5=1 , gen(linos_hr) 
recode linos_i 1=5 2=4 3=3 4=2 5=1 , gen(linos_ir) 

* Equality
recode linos_c 1=5 2=4 3=3 4=2 5=1 , gen(linos_cr) 
recode linos_k 1=5 2=4 3=3 4=2 5=1 , gen(linos_kr) 
recode linos_g 1=5 2=4 3=3 4=2 5=1 , gen(linos_gr) 

* Need
recode linos_e 1=5 2=4 3=3 4=2 5=1 , gen(linos_er) 
recode linos_j 1=5 2=4 3=3 4=2 5=1 , gen(linos_jr) 
recode linos_a 1=5 2=4 3=3 4=2 5=1 , gen(linos_ar) 

* Entitlement
recode linos_d 1=5 2=4 3=3 4=2 5=1 , gen(linos_dr) 
recode linos_l 1=5 2=4 3=3 4=2 5=1 , gen(linos_lr) 
recode linos_f 1=5 2=4 3=3 4=2 5=1 , gen(linos_fr) 

* Merit = Equity
gen linos = linos_br +linos_hr +linos_ir 
gen merit01 = (linos-3)/12
label var merit01 "Preference for Merit Principle "

* Equality
gen linos2 = linos_cr +linos_kr +linos_gr 
gen equality01 = (linos2-3)/12
label var equality01 "Preference for Equality Principle "

* Need
gen linos3 = linos_er +linos_jr +linos_ar 
gen need01 = (linos3-3)/12
label var need01 "Preference for Need Principle "

* Entitlement
gen linos4 = linos_dr +linos_lr +linos_fr 
gen entit01 = (linos4-3)/12
label var entit01 "Preference for Entitlement Principle "

* Lab
recode lab 1=0 2=1, gen(lab2)


*** Analysis  

* Fig. 2 
twoway kdensity  correct      if rate==3, lcolor (black) lpattern(dash)  || ///
       kdensity  correct      if rate==6  || ///
       kdensity  correct      if rate==9 , ///
       lcolor (grey) lpattern(dot) legend(order(1 "Low" 2 "Medium" 3 "High") rows(1) position(6)) xtitle("Correctly Solved Tasks") ytitle("Density")
graph save fig0a.gph, replace
twoway kdensity  bruttoincome if rate==3, lcolor (black) lpattern(dash)  || ///
       kdensity  bruttoincome if rate==6  || ///
	   kdensity  bruttoincome if rate==9 ,   ///
	   lcolor (grey) lpattern(dot) legend(order(1 "Low" 2 "Medium" 3 "High") rows(1) position(6)) xtitle("Pre-tax Income") ytitle("Density")
graph save fig0b.gph, replace
graph combine fig0a.gph fig0b.gph, xsize(4) ysize(2)
graph save fig2_fin.gph, replace 
erase fig0a.gph
erase fig0b.gph


* Fig. 3
fvset base 6  rate
vcemway xtreg correct i.rate##i.treat5  c.leftright age fem sem study1 study3 study4 study5 i.lab i.period  ,  cluster(id sessionid)
est store m1
margins rate#treat5
marginsplot,  title("") bydimension(treat5) recast(scatter)  ytitle(Conditional mean correctly solved tasks, size(medium)) ///
              xtitle(Rate) xlabel(3 "Low"  6 "Medium" 9 "High") xtitle("")
graph save fig3_fin.gph, replace	  
esttab m1 using tab_a2.csv, se(2) brackets star(* 0.10 ** 0.05 *** 0.01) scalars(r2 r2_a r2_w r2_o r2_b)  nogaps replace label  nobaselevels


* Fig. 4
tsset id period
fvset base 1  treat5
vcemway fracreg logit  decision01 i.treat5    ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
est store m1
margins i.treat5,  level(95)
marginsplot, recast(scatter)  ytitle(Conditional mean of tax decision, size(medium)) title("") xtitle(Treatment) xlabel(, angle(45))
graph save fig4_fin.gph, replace

* Fig. 5a, b
vcemway fracreg logit  decision01 i.treat5    ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(ginc_d=(-300(50)400))
marginsplot,  title("") xline(0 , lpattern(dash)) ytitle(Conditional mean of tax decision, size(medium)) xtitle(Pre-Tax Income - Av. Group Income) xlabel(, angle(45)) ///
			  addplot(hist ginc_d, /// 
              blcolor(gs10) fcolor(gs10) /// 
              percent /// 
              yaxis(2) /// 
              yscale(alt lcolor() axis(2)) /// 
              ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%", /// 
              labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
              ytitle(" ", axis(2)) color(%30) /// 
              legend(order( 2 "Predicted" 3 "Percent")))
			  graph save fig5a_fin.gph, replace
vcemway fracreg logit  decision01 i.treat5    ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(leftright=(0(.1)1))
marginsplot,  title("")  ytitle(Conditional mean of tax decision, size(medium)) xtitle(Left Right) xlabel(, angle(45)) ///
			  addplot(hist leftright, /// 
              blcolor(gs10) fcolor(gs10) /// 
              percent ///
              yaxis(2) /// 
              yscale(alt lcolor() axis(2)) /// 
              ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%", ///
              labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// l
              ytitle(" ", axis(2)) color(%30) /// 
              legend(order( 2 "Predicted" 3 "Percent")))
			  graph save fig5b_fin.gph, replace	
vcemway fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
estimates store m2
vcemway fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
est store m3

* Tab. 2
esttab m1 m2 m3  using tab_2.csv, se(2) brackets star(* 0.10 ** 0.05 *** 0.01) pr2 aic bic nogaps replace label  nobaselevels


* Fig 6a, b, c
vcemway fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(ginc_d=(-300(50)400) treat5=1) saving(file1, replace) 
vcemway fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(ginc_d=(-300(50)400) treat5=2)  saving(file2, replace)
vcemway fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(ginc_d=(-300(50)400) treat5=3) saving(file3, replace)
vcemway fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(ginc_d=(-300(50)400) treat5=4) saving(file4, replace) 
vcemway fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(ginc_d=(-300(50)400) treat5=5) saving(file5, replace)  
combomarginsplot        file2 file3,  title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Pre-Tax Income - Av. Group Income) xlabel(, angle(45)) ///
                        addplot(hist ginc_d, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// c
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) color(%30) ///				   
					    legend(order( 3 "Merit rule with full info." 4 "Luck rule with full info" ))) 
						graph save fig6a_fin.gph, replace
combomarginsplot        file2 file1,  title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Pre-Tax Income - Av. Group Income) xlabel(, angle(45)) ///
                        addplot(hist ginc_d, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) color(%30) /// 				   
					    legend(order( 3 "Merit rule with full info." 4 "Equal pay" )))	
						graph save fig6b_fin.gph, replace
combomarginsplot        file4 file5,  title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Pre-Tax Income - Av. Group Income) xlabel(, angle(45)) ///
                        addplot(hist ginc_d, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) ///
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) color(%30) ///					   
					    legend(order( 3 "Merit rule without information" 4 "Luck rule without information" )))
						graph save fig6c_fin.gph, replace
erase file1.dta 
erase file2.dta
erase file3.dta 
erase file4.dta
erase file5.dta
																				
* Fig. 7a, b, c 
vcemway fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.leftright = (0(.1)1) treat5=1) saving(file1, replace)
vcemway fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.leftright = (0(.1)1) treat5=2) saving(file2, replace)
vcemway fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.leftright = (0(.1)1) treat5=3) saving(file3, replace)
vcemway fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.leftright = (0(.1)1) treat5=4) saving(file4, replace)
vcemway fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.leftright = (0(.1)1) treat5=5) saving(file5, replace)
combomarginsplot        file2 file3,  title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Left Right) xlabel(, angle(45)) ///
                        addplot(hist leftright, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) ylabel(0(.2).8) color(%30) /// 					   
					    legend(order( 3 "Merit rule with full info." 4 "Luck rule with full info." ))) 
						graph save fig7a_fin.gph, replace
combomarginsplot        file2 file1,  title("")  ytitle(Conditional mean of tax decision, size(medium))   xtitle(Left Right) xlabel(, angle(45)) ///
                        addplot(hist leftright, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) ylabel(0(.2).8) color(%30) /// 					   
					    legend(order( 3 "Merit rule with full info." 4 "Equal pay" )))	
						graph save fig7b_fin.gph, replace						
combomarginsplot        file4 file5,  title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Left Right) xlabel(, angle(45)) ///
                        addplot(hist leftright, ///
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) ///
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) ylabel(0(.2).8) color(%30) /// 				   
					    legend(order( 3 "Merit rule without information" 4 "Luck rule without information" )))
						graph save fig7c_fin.gph, replace
erase file1.dta 
erase file2.dta
erase file3.dta 
erase file4.dta
erase file5.dta						
						
						
* Appendix Tab. 1
tabstat leftright merit01 equality01 need01 entit01 age fem sem study1 study2 study3 study4 study5 lab2, by(treat5) stat(mean sd)


* Online Appendix Tab. 1
mlogit treat5 leftright age fem sem study1 study3 study4 study5 i.lab if period==1,  base(1) robust
est store m1
esttab m1 using tab_a1.csv, se(2) brackets star(* 0.10 ** 0.05 *** 0.01) pr2 aic bic nogaps replace label  nobaselevels

* Online Appendix Tab. 3
pwcorr leftright merit01 equality01 need01 entit01 if period==1, sig obs

* Online Appendix Tab. 4
tsset id period
fracreg logit  decision01 i.treat5    ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period ,  vce(cluster id)
est store m1
fracreg logit  decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period ,  vce(cluster id)
est store m2
fracreg logit  decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period ,  vce(cluster id)
est store m3
xtreg decision01 i.treat5    ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period ,  re vce(cluster id)
est store m1b
xtreg decision01 i.treat5##c.ginc_d           c.leftright age fem sem study1 study3 study4 study5 i.lab i.period ,  re vce(cluster id)
est store m2b
xtreg decision01 i.treat5##c.leftright    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period ,  re vce(cluster id)
est store m3b
esttab m1 m1b m2 m2b m3 m3b  using tab_a4.csv, se(2) brackets star(* 0.10 ** 0.05 *** 0.01) pr2 aic bic nogaps replace label  nobaselevels

* Online Appendix Fig. 2
vcemway fracreg logit  decision01 i.treat5##c.merit01    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.merit01 = (0(.1)1) treat5=1) saving(file1, replace)
vcemway fracreg logit  decision01 i.treat5##c.merit01    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.merit01 = (0(.1)1) treat5=2) saving(file2, replace)
vcemway fracreg logit  decision01 i.treat5##c.merit01    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.merit01 = (0(.1)1) treat5=3) saving(file3, replace)
vcemway fracreg logit  decision01 i.treat5##c.merit01    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.merit01 = (0(.1)1) treat5=4) saving(file4, replace)
vcemway fracreg logit  decision01 i.treat5##c.merit01    ginc_d          age fem sem study1 study3 study4 study5 i.lab i.period , cluster(id sessionid)
margins , at(c.merit01 = (0(.1)1) treat5=5) saving(file5, replace)
combomarginsplot        file2 file3,  title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Merit Preference) ///
                        addplot(hist merit01, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) ylabel(0(.2).8) color(%30) /// 				   
					    legend(order( 3 "Merit rule with full info." 4 "Luck rule with full info." ))) 						
combomarginsplot        file2 file1, title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Merit Preference) ///
                        addplot(hist merit01, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) ylabel(0(.2).8) color(%30) /// 					   
					    legend(order( 3 "Merit rule with full info." 4 "Equal pay" ))) 				
combomarginsplot        file4 file5, title("")  ytitle(Conditional mean of tax decision, size(medium))  xtitle(Merit Preference) ///
                        addplot(hist merit01, /// 
                        blcolor(gs10) fcolor(gs10) /// 
                        percent /// 
                        yaxis(2) /// 
                        yscale(alt lcolor() axis(2)) /// 
                        ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" 60 "60%" 70 "70%" 80 "80%", /// 
                        labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// 
                        ytitle(" ", axis(2)) ylabel(0(.2).8) color(%30) /// 				   
					    legend(order( 3 "Merit rule without information" 4 "Luck rule without information" )))
erase file1.dta 
erase file2.dta
erase file3.dta 
erase file4.dta
erase file5.dta						


*** End of Replication File ***
